/* This file is part of LlamaSlayers Ajax Chat
 *
 * The source code is released under the GNU GPL free software license, version 3.
 * Updates can be found at http://llamaslayers-ajax-chat.googlecode.com/
 */
$(function(){
	$.getJSON(
		'user.php',
		{g: 'availicons'},
		function (icons){
			$('div').text('Click on a set of icons to change your icon.');
			var alt = false;
			$.each(icons, function(){
				var icon = this+'';
				$('<div/>').css({
					backgroundColor: alt ? '#fff' : '#f7f7f7'
				}).append($('<img/>').attr({
					src: 'icons/' + icon + '_small.png',
					width: 15,
					height: 15
				})).append($('<img/>').attr({
					src: 'icons/' + icon + '_large.png',
					width: 48,
					height: 48
				})).one('click', function(){
					$('div').not(this).hide('normal');
					$.get(
						'user.php',
						{g: 'seticon', i: icon},
						function(result){
							if (result == '1') {
								$('div').animate(
									{backgroundColor: '#ffb'},
									'normal'
								);
							} else {
								$('div').animate(
									{backgroundColor: '#fbb'},
									'normal'
								);
							}
						},
						'text'
					);
				}).hide().appendTo('body').show('normal');
				alt = !alt;
			});
		}
	);
});